package com.mobiletrain.org.motherkitch.shequ;

import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by lenovo on 2015/4/26.
 */
public class SheQuDetailReplyAdapter extends BaseAdapter{
    private Context context;
    private LayoutInflater inflater;
    private ArrayList<SheQuDetailReplyClass> data;

    public SheQuDetailReplyAdapter(Context context, ArrayList<SheQuDetailReplyClass> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DetailReplyViewHolder holder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.shequdetailreplay_list_item,null);
            holder = new DetailReplyViewHolder();
            holder.image = (ImageView) convertView.findViewById(R.id.image);
            holder.title = (TextView) convertView.findViewById(R.id.nickname);
            holder.floor = (TextView) convertView.findViewById(R.id.floor);
            holder.age_str = (TextView) convertView.findViewById(R.id.age_str);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            holder.date = (TextView) convertView.findViewById(R.id.date);
            holder.city = (TextView) convertView.findViewById(R.id.city);
            convertView.setTag(holder);
        }else{
            holder = (DetailReplyViewHolder) convertView.getTag();
        }
        SheQuDetailReplyClass sheQuDetailReplyClass = data.get(position);
        BitmapUtils bitmapUtils = ImageLoad.getBitmapUtils(context);
        bitmapUtils.display(holder.image,sheQuDetailReplyClass.getAvatar());
        holder.title.setText(sheQuDetailReplyClass.getNickname());
        holder.age_str.setText(sheQuDetailReplyClass.getAge_str());
        holder.city.setText(sheQuDetailReplyClass.getCity());
        holder.content.setText(sheQuDetailReplyClass.getContent()+sheQuDetailReplyClass.getPic());
        holder.date.setText(sheQuDetailReplyClass.getShow_date());
        holder.floor.setText(position+1+"楼");
        return convertView;
    }
    class DetailReplyViewHolder{
        ImageView image;
        TextView title;
        TextView floor;
        TextView age_str;
        TextView content;
        TextView date;
        TextView city;
    }
}
